package com.pengtu.entity.detect;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.GenericGenerator;

import com.pengtu.utils.MathsUtils;

/**
 * Bridgespot.
 */
@Entity
@Table(name = "S_Q_DETECT_BRIDGESPOT")
public class Bridgespot {

	/**
	 * serialVersionUID:TODO
	 * 
	 * @since 1.0.0
	 */

	private static final long serialVersionUID = 1L;

	private String projectId;
	private Integer countF401;
	private Integer passF401;
	private Integer countF402;
	private Integer passF402;
	private Integer countF403;
	private Integer passF403;
	private Integer countF404;
	private Integer passF404;
	private Integer countF405;
	private Integer passF405;
	private Integer countF406;
	private Integer passF406;
	private Integer countF407;
	private Integer passF407;
	private Integer countF408;
	private Integer passF408;
	private Date reportdate;
	private String remark;
	private SpotReport spotReport;
	private String id;
	private String groupBy;
	private Date createDate; // 创建时间
	
	public Bridgespot(){
	}
	public Bridgespot(Long countF401, Long passF401, Long countF402,
			Long passF402, Long countF403, Long passF403,
			Long countF404, Long passF404, Long countF405,
			Long passF405, Long countF406, Long passF406,
			Long countF407, Long passF407,Long countF408, Long passF408) {
		this.countF401 = countF401 == null ? null : countF401.intValue();
		this.passF401 = passF401 == null ? null : passF401.intValue();
		this.countF402 = countF402 == null ? null : countF402.intValue();
		this.passF402 = passF402 == null ? null : passF402.intValue();
		this.countF403 = countF403 == null ? null : countF403.intValue();
		this.passF403 = passF403 == null ? null : passF403.intValue();
		this.countF404 = countF404 == null ? null : countF404.intValue();
		this.passF404 = passF404 == null ? null : passF404.intValue();
		this.countF405 = countF405 == null ? null : countF405.intValue();
		this.passF405 = passF405 == null ? null : passF405.intValue();
		this.countF406 = countF406 == null ? null : countF406.intValue();
		this.passF406 = passF406 == null ? null : passF406.intValue();
		this.countF407 = countF407 == null ? null : countF407.intValue();
		this.passF407 = passF407 == null ? null : passF407.intValue();
		this.countF408 = countF408 == null ? null : countF408.intValue();
		this.passF408 = passF408 == null ? null : passF408.intValue();
	}
	public Bridgespot(Long countF401, Long passF401, Long countF402,
			Long passF402, Long countF403, Long passF403,
			Long countF404, Long passF404, Long countF405,
			Long passF405, Long countF406, Long passF406,
			Long countF407, Long passF407,Long countF408, Long passF408,String groupBy) {
		this.countF401 = countF401 == null ? null : countF401.intValue();
		this.passF401 = passF401 == null ? null : passF401.intValue();
		this.countF402 = countF402 == null ? null : countF402.intValue();
		this.passF402 = passF402 == null ? null : passF402.intValue();
		this.countF403 = countF403 == null ? null : countF403.intValue();
		this.passF403 = passF403 == null ? null : passF403.intValue();
		this.countF404 = countF404 == null ? null : countF404.intValue();
		this.passF404 = passF404 == null ? null : passF404.intValue();
		this.countF405 = countF405 == null ? null : countF405.intValue();
		this.passF405 = passF405 == null ? null : passF405.intValue();
		this.countF406 = countF406 == null ? null : countF406.intValue();
		this.passF406 = passF406 == null ? null : passF406.intValue();
		this.countF407 = countF407 == null ? null : countF407.intValue();
		this.passF407 = passF407 == null ? null : passF407.intValue();
		this.countF408 = countF408 == null ? null : countF408.intValue();
		this.passF408 = passF408 == null ? null : passF408.intValue();
		this.groupBy = groupBy;
	}
	
	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	@Column(length = 48)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(nullable = false, updatable = false, name = "CREATEDATE")
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	@OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
	@JoinColumn(name = "SID")
	public SpotReport getSpotReport() {
		return spotReport;
	}

	public void setSpotReport(SpotReport spotReport) {
		this.spotReport = spotReport;
	}

	@Column(name = "PID")
	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	@Column(name = "COUNT_F401", precision = 22, scale = 0)
	public Integer getCountF401() {
		return this.countF401;
	}

	public void setCountF401(Integer countF401) {
		this.countF401 = countF401;
	}

	@Column(name = "PASS_F401", precision = 22, scale = 0)
	public Integer getPassF401() {
		return this.passF401;
	}

	public void setPassF401(Integer passF401) {
		this.passF401 = passF401;
	}

	@Transient
	public Double getPassrateF401() {
		Double a = MathsUtils.div("2", getPassF401(), getCountF401(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Column(name = "COUNT_F402", precision = 22, scale = 0)
	public Integer getCountF402() {
		return this.countF402;
	}

	public void setCountF402(Integer countF402) {
		this.countF402 = countF402;
	}

	@Column(name = "PASS_F402", precision = 22, scale = 0)
	public Integer getPassF402() {
		return this.passF402;
	}

	public void setPassF402(Integer passF402) {
		this.passF402 = passF402;
	}

	@Transient
	public Double getPassrateF402() {
		Double a = MathsUtils.div("2", getPassF402(), getCountF402(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Column(name = "COUNT_F403", precision = 22, scale = 0)
	public Integer getCountF403() {
		return this.countF403;
	}

	public void setCountF403(Integer countF403) {
		this.countF403 = countF403;
	}

	@Column(name = "PASS_F403", precision = 22, scale = 0)
	public Integer getPassF403() {
		return this.passF403;
	}

	public void setPassF403(Integer passF403) {
		this.passF403 = passF403;
	}

	@Transient
	public Double getPassrateF403() {
		Double a = MathsUtils.div("2", getPassF403(), getCountF403(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Column(name = "COUNT_F404", precision = 22, scale = 0)
	public Integer getCountF404() {
		return this.countF404;
	}

	public void setCountF404(Integer countF404) {
		this.countF404 = countF404;
	}

	@Column(name = "PASS_F404", precision = 22, scale = 0)
	public Integer getPassF404() {
		return this.passF404;
	}

	public void setPassF404(Integer passF404) {
		this.passF404 = passF404;
	}

	@Transient
	public Double getPassrateF404() {
		Double a = MathsUtils.div("2", getPassF404(), getCountF404(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Column(name = "COUNT_F405", precision = 22, scale = 0)
	public Integer getCountF405() {
		return this.countF405;
	}

	public void setCountF405(Integer countF405) {
		this.countF405 = countF405;
	}

	@Column(name = "PASS_F405", precision = 22, scale = 0)
	public Integer getPassF405() {
		return this.passF405;
	}

	public void setPassF405(Integer passF405) {
		this.passF405 = passF405;
	}

	@Transient
	public Double getPassrateF405() {
		Double a = MathsUtils.div("2", getPassF405(), getCountF405(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Column(name = "COUNT_F406", precision = 22, scale = 0)
	public Integer getCountF406() {
		return this.countF406;
	}

	public void setCountF406(Integer countF406) {
		this.countF406 = countF406;
	}

	@Column(name = "PASS_F406", precision = 22, scale = 0)
	public Integer getPassF406() {
		return this.passF406;
	}

	public void setPassF406(Integer passF406) {
		this.passF406 = passF406;
	}

	@Transient
	public Double getPassrateF406() {
		Double a = MathsUtils.div("2", getPassF406(), getCountF406(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Column(name = "COUNT_F407", precision = 22, scale = 0)
	public Integer getCountF407() {
		return this.countF407;
	}

	public void setCountF407(Integer countF407) {
		this.countF407 = countF407;
	}

	@Column(name = "PASS_F407", precision = 22, scale = 0)
	public Integer getPassF407() {
		return this.passF407;
	}

	public void setPassF407(Integer passF407) {
		this.passF407 = passF407;
	}

	@Transient
	public Double getPassrateF407() {
		Double a = MathsUtils.div("2", getPassF407(), getCountF407(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}

	@Column(name = "COUNT_F408", precision = 22, scale = 0)
	public Integer getCountF408() {
		return countF408;
	}
	public void setCountF408(Integer countF408) {
		this.countF408 = countF408;
	}
	
	@Column(name = "PASS_F408", precision = 22, scale = 0)
	public Integer getPassF408() {
		return passF408;
	}
	public void setPassF408(Integer passF408) {
		this.passF408 = passF408;
	}
	
	@Transient
	public Double getPassrateF408() {
		Double a = MathsUtils.div("2", getPassF408(), getCountF408(), 0.01);
		if(a==0){
			a = null;
		}
		return a;
	}
	
	@Temporal(TemporalType.DATE)
	@Column(name = "REPORTDATE", length = 7)
	public Date getReportdate() {
		return this.reportdate;
	}

	public void setReportdate(Date reportdate) {
		this.reportdate = reportdate;
	}

	@Column(name = "REMARK", length = 400)
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

	@Transient
	public double getCountF400() {
		return MathsUtils.sum(getCountF401(), getCountF402(), getCountF403(),
				getCountF404(), getCountF405(), getCountF406(), getCountF407(), getCountF408());
	}

	@Transient
	public double getPassF400() {
		return MathsUtils.sum(getPassF401(), getPassF402(), getPassF403(),
				getPassF404(), getPassF405(), getPassF406(), getPassF407(), getPassF408());
	}

	@Transient
	public double getPassrateF400() {
		if (getPassF400() == 0) {
			return 0;
		} else {
			return MathsUtils.div("2", getPassF400(), getCountF400(),
					0.01);
		}
	}
	@Transient
	public String getGroupBy() {
		return this.groupBy;
	}
}
